import { Decrypter } from "@/utils/Decrypter.js";
export class ResourceLoader{
    /**
     * 
     * @param {string} src 
     * @returns {Promise<ImageBitmap>}
     */
    static async loadImageBitmap(src){
        let blob=null;
        if(window.$dataSystem?.hasEncryptedImages){
            let url=Decrypter.extToEncryptExt(src);
            let response=await fetch(url);
            let input=await response.arrayBuffer();
            let output=Decrypter.decryptArrayBuffer(input);
            blob=new Blob([output],{type:'image/png'});
        }else{

            let response=await fetch(src);
            blob=await response.blob();   
        }
        let bitmap=await createImageBitmap(blob); 
        
        return bitmap;
    }
    /**
     * 
     * @param {string} src
     * @returns {Promise<ArrayBuffer>} 
     */
    static async loadEncrypterSound(src){
        let url=Decrypter.extToEncryptExt(src);
        let response=await fetch(url);
        let arrayBuffer=await response.arrayBuffer();
        return Decrypter.decryptArrayBuffer(arrayBuffer);
    }
}